﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using FlexCell;

namespace ModelChecking.PerformanceAnalysis.AreaRatioWindowToWall
{
	internal class AreaRatioExportToView
	{
		public ResultMaker ResultMaker
		{
			get
			{
				return this.m_ResultMaker;
			}
		}

		public double NorthAreaRatio
		{
			get
			{
				return this.m_NorthAreaRatio;
			}
		}

		public double SouthAreaRatio
		{
			get
			{
				return this.m_SouthAreaRatio;
			}
		}

		public double WestAreaRatio
		{
			get
			{
				return this.m_WestAreaRatio;
			}
		}

		public double EastAreaRatio
		{
			get
			{
				return this.m_EastAreaRatio;
			}
		}

		public FlexCell.Grid AreaRatioGrid
		{
			get
			{
				return this.m_AreaRatioGrid;
			}
		}

		internal AreaRatioExportToView(Autodesk.Revit.DB.Document doc, ResultMaker resultMaker)
		{
			this.m_Doc = doc;
			this.m_ResultMaker = resultMaker;
            this.m_AreaRatioGrid = new FlexCell.Grid();
		}

		public void CalAreaRatio()
		{
			List<AreaRatioStructMaker> areaRatioStructMakerList = this.m_ResultMaker.AreaRatioStructMakerList;
			this.m_NorthAreaRatio = this.CalAreaRatioInFacade(areaRatioStructMakerList, FacadeDirection.NorthFacade);
			this.m_SouthAreaRatio = this.CalAreaRatioInFacade(areaRatioStructMakerList, FacadeDirection.SouthFacade);
			this.m_WestAreaRatio = this.CalAreaRatioInFacade(areaRatioStructMakerList, FacadeDirection.WestFacade);
			this.m_EastAreaRatio = this.CalAreaRatioInFacade(areaRatioStructMakerList, FacadeDirection.EastFacade);
		}

		private double CalAreaRatioInFacade(List<AreaRatioStructMaker> areaRatioStructMakerList, FacadeDirection direction)
		{
			double num = 0.0;
			double num2 = 0.0;
			foreach (AreaRatioStructMaker areaRatioStructMaker in areaRatioStructMakerList)
			{
				switch (direction)
				{
				case FacadeDirection.NorthFacade:
					this.CalArea(areaRatioStructMaker.NorthAreaRatioStructList, ref num, ref num2);
					break;
				case FacadeDirection.SouthFacade:
					this.CalArea(areaRatioStructMaker.SouthAreaRatioStructList, ref num, ref num2);
					break;
				case FacadeDirection.WestFacade:
					this.CalArea(areaRatioStructMaker.WestAreaRatioStructList, ref num, ref num2);
					break;
				case FacadeDirection.EastFacade:
					this.CalArea(areaRatioStructMaker.EastAreaRatioStructList, ref num, ref num2);
					break;
				}
			}
			if (num == 0.0)
			{
				return 0.0;
			}
			return Math.Round(num2 / num, 2);
		}

		private void CalArea(List<AreaRatioStruct> AreaRatioStructList, ref double wallArea, ref double caveArea)
		{
			foreach (AreaRatioStruct areaRatioStruct in AreaRatioStructList)
			{
				wallArea += areaRatioStruct.WallArea;
				caveArea += areaRatioStruct.CaveArea;
			}
		}

		public void AreaRatioGridInit()
		{
			int cols = 4;
			int rows = 6;
			this.m_AreaRatioGrid.Cols = cols;
			this.m_AreaRatioGrid.Rows = rows;
			this.m_AreaRatioGrid.Cell(1, 1).Text = "窗墙比";
			this.m_AreaRatioGrid.Cell(1, 2).Text = "方向";
			this.m_AreaRatioGrid.Cell(1, 3).Text = "设计值";
			this.m_AreaRatioGrid.Cell(2, 2).Text = "东";
			this.m_AreaRatioGrid.Cell(2, 3).Text = this.EastAreaRatio.ToString();
			this.m_AreaRatioGrid.Cell(3, 2).Text = "南";
			this.m_AreaRatioGrid.Cell(3, 3).Text = this.SouthAreaRatio.ToString();
			this.m_AreaRatioGrid.Cell(4, 2).Text = "西";
			this.m_AreaRatioGrid.Cell(4, 3).Text = this.WestAreaRatio.ToString();
			this.m_AreaRatioGrid.Cell(5, 2).Text = "北";
			this.m_AreaRatioGrid.Cell(5, 3).Text = this.NorthAreaRatio.ToString();
			this.m_AreaRatioGrid.Range(1, 1, 5, 1).Merge();
			this.m_AreaRatioGrid.Cell(1, 1).Alignment = AlignmentEnum.CenterCenter;
		}

		private Document m_Doc;

		private ResultMaker m_ResultMaker;

		private double m_NorthAreaRatio;

		private double m_SouthAreaRatio;

		private double m_WestAreaRatio;

		private double m_EastAreaRatio;

        private FlexCell.Grid m_AreaRatioGrid;
	}
}
